package com.elink.enginerring.postbar;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.elink.enginerring.datasource.DataSourceContextHolder;
import com.elink.enginerring.datasource.DataSourceType;
import com.elink.enginerring.postbar.service.IPostbarService;

/**
 * 百问百答
 * @author hxjxiaojun
 *@time 2017年1月5日
 */
@Controller
@RequestMapping("/view/postbar")
@Api(value="百问百答接口")
public class PostbarController {
  @Autowired
  private IPostbarService postbarService;
  
	/**
	 * 百问百答列表
	 * @param co
	 * @return
	 */
  @RequestMapping(value = "/getList",method = RequestMethod.GET)
  @ApiOperation(value="百问百答列表",httpMethod="GET",notes="分页获取百问百答列表")
  @ResponseBody
  public Map<String, Object>getList(@ModelAttribute @Valid PostbarCo co){
		DataSourceContextHolder.setDbType(DataSourceType.DBPOSTBAR);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		
	  return postbarService.getList(co);
  }
  
	/**
	 * 审核问答
	 * @param ids
	 * @return
	 */
	@RequestMapping(value="/addAuth",method=RequestMethod.GET)
	@ApiOperation(value="审核问答",httpMethod="GET",notes="审核问答")
	@ResponseBody
	public Map<String, Object>addAuth(
	@ApiParam(value="问答主键ids，用逗号进行分割",required=true)@RequestParam(value="ids",required=true)String ids,
	@ApiParam(value="处理意见，1--审核通过，2--不通过审核",required=true)@RequestParam(value="authStatus",required=true,defaultValue="0")int authStatus){
		DataSourceContextHolder.setDbType(DataSourceType.DBPOSTBAR);
		System.out.println("选择的数据库" + DataSourceContextHolder.getDbType());
		return postbarService.addAuth(ids,authStatus);
	}
}
